package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.IndexDeviceInfo;
import com.dwxt.sport.business.service.IndexDeviceInfoService;
import com.dwxt.sport.business.service.StreetDeviceClassifyService;
import com.dwxt.sport.business.view.DistributionMapView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 首页相关 接口
 *
 * @author Kuang.JiaZhuo
 * @date 2020-08-11 14:18
 */
@RestController
@RequestMapping("/index")
@Api(tags={"首页相关接口"})
public class IndexController {

    @Resource
    IndexDeviceInfoService indexDeviceInfoService;

    @Resource
    StreetDeviceClassifyService streetDeviceClassifyService;

    @ApiOperation(value = "新增或修改【首页-设备统计】", notes = "新增或修改【首页-设备统计】", response = Integer.class)
    @PostMapping("/back/insertOrUpdateStreetDeviceClassify")
    public BaseResult insertOrUpdateStreetDeviceClassify(
            @ApiParam(value = "ID(新增不传,更新必传)") @RequestParam(required = false) String id,
            @ApiParam(value = "设备分类(关联数据字典【classification】)", required = true) @RequestParam String classification,
            @ApiParam(value = "设备数量", required = true) @RequestParam Integer equipmentNumber,
            @ApiParam(value = "启用数量", required = true) @RequestParam Integer enableAmount,
            @ApiParam(value = "监测异常的数量", required = true) @RequestParam Integer anomalyCount
    ){
        IndexDeviceInfo indexDeviceInfo = new IndexDeviceInfo().setId(id)
                .setClassification(classification).setClassification(classification)
                .setEquipmentNumber(equipmentNumber).setEnableAmount(enableAmount)
                .setAnomalyCount(anomalyCount);
        int result = this.indexDeviceInfoService.insertOrUpdateStreetDeviceClassify(indexDeviceInfo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "获取【首页-设备统计】数据", notes = "获取【首页-设备统计】数据", response = IndexDeviceInfo.class)
    @PostMapping("/selectIndexDeviceInfoList")
    public BaseResult selectIndexDeviceInfoList(){
        List<IndexDeviceInfo> list = this.indexDeviceInfoService.selectIndexDeviceInfoList();
        return BaseResult.ok(list);
    }

    @ApiOperation(value = "删除【首页-设备统计】", notes = "根据ids批量删除【首页-设备统计】", response= Integer.class)
    @PostMapping(value = "/back/deletetStreetDeviceClassifyByIds")
    public BaseResult deletetStreetDeviceClassifyByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.indexDeviceInfoService.deletetStreetDeviceClassifyByIds(ids);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "查询首页-智能物联分布地图", notes = "根据设备分类查询[首页-智能物联分布]地图", response= DistributionMapView.class)
    @PostMapping(value = "/selectDistributionMapViewByClassification")
    public BaseResult selectDistributionMapViewByClassification(@ApiParam(value = "设备分类集合(关联数据字典【classification】)") @RequestParam(required = false) String[] classificationList){
        System.err.println("接口打印=="+classificationList);
        List<DistributionMapView> list = this.streetDeviceClassifyService.selectDistributionMapViewByClassification(classificationList);
        return BaseResult.ok(list);
    }


}
